<?php
namespace Admin\Controller;

class SxzController extends AdminController
{

  public function index(){
             $name          = I('get.name');
        $map['status'] = array('egt', 0);
        if (is_numeric($name)) {
            $map['id|name'] = array(intval($name), array('like', '%' . $name . '%'), '_multi' => true);
        } else {
            $map['name'] = array('like', '%' . (string) $name . '%');
        }

        $res = $this->lists('attrval', $map);
        // $res = M('attrval')->select();
        $a=M('attrkey')->getField('id,keyname');
        $b=M('attrkey')->getField('gid,goodname');
        $this->assign('a',$a);
        $this->assign('b',$b);
        $this->assign('res', $res);
        $this->display(); 
  }


  public function add(){
      if (IS_GET) {
      $s=I('get.');
      $this->assign('res',$s);
      $this->display();
      } else {
      	  $b=I('post.');
           // dump($b);die;
          $data=M('attrval')->add($b);
           // dump($data);die;
          if ($data) {
          $this->success('属性值添加成功', U('index'));
          } else {
          $this->error('属性值添加失败');
           }
      }


  }

    public function update()
    {
            if (IS_GET) {
            $id=I('get.id');
            $res=M('attrval')->where(['id'=>$id])->select();
            // dump($res);
            $this->assign('res1',$res);
            $this->display();
         } else {
         	$post=I('post.');
         	// dump($post);die;
         	$data=M('attrval')->where(['id' => I('post.ooid')])->save($post);
            if ($data) {
               
                $this->success('编辑属性值成功', U('index'));
            } else {
                $this->error('编辑属性值失败');
            }
        }
  
    }



















    public function changeStatus($method = null)
    {
        $id = array_unique((array) I('id', 0));

        $id = is_array($id) ? implode(',', $id) : $id;
        if (empty($id)) {
            $this->error('请选择要操作的数据!');
        }
        $map['id'] = array('in', $id);
        switch (strtolower($method)) {
            case 'del':
                M('attrval')->where($map)->delete();
                $this->success('删除成功');
                break;
            default:
                $this->error('参数非法');
        }
    }










}